from django.shortcuts import render
from django.http import HttpResponse
from polls.model.entity import *

# Create your views here.

emp1 = entity()


def toLogin_view(request):
    return render(request, 'login.html')


def Login_view(request):
    u = request.GET.get("user", '')
    p = request.GET.get("pwd", '')
    print(u)
    print(p)

    if u and p:
        return HttpResponse('success')
    else:
        return HttpResponse('rejust')


def findBlogs(request):
    url = request.POST.get("url",'')
    print(url)
    # "https://blog.csdn.net/pythonxuexi123/article/list"
    emp1.get_all_article(url)
    allInfo = ''
    for i in range(len(emp1.Titles)):
        allInfo += emp1.Titles[i] + ",,!,!,,"
        for j in range(len(emp1.blogtag_id[i])):
            allInfo += emp1.blogtag_id[i][j] + ",!,!,"
        allInfo += ",,!,!,," + emp1.links[i] + ",,!,!,,"
    print(allInfo)
    return HttpResponse(allInfo)


def selectBlogs(request):
    s = request.POST.get('select','')
    print(s)
    list = s.split(',')
    listSelect = []
    for i in list:
        listSelect.append(int(i))
    print(listSelect)
    emp1.get_data_1(listSelect)
    return HttpResponse('success')